<?php
/**
 * Created by PhpStorm.
 * User: 68008000
 * Date: 2017/11/30
 * Time: 13:31
 */

namespace app\index\controller;


use think\Controller;

/**
 * Class Order
 * @package app\index\controller
 * 订单详情控制器
 */
class Order extends Controller
{
    protected $db;
    public function __construct()
    {
        parent::__construct();
        $this->db = new \app\common\model\Order();
    }
    public function index(){
        //处理title
        $conf = ['title'=>'阿里巴巴1688.com - 订单详情','css'=>'order','js'=>'order'];
        $this->assign('conf',$conf);
        $cart = session('cart');
        p($cart);
        $this->assign('cart',$cart);
        $addressData = db('receiving_address')->limit(2)->select();
        $this->assign('addressData',$addressData);
        //视图
        return view();
    }
    //添加地址
    public function address(){
        if(request()->isPost()){
        $data=input('post.');
        $res=$this->db->address($data);
        if ($res['valid']) {
            $this->success($res['msg'],'index');
        } else {
            $this->error($res['msg']);
        }
    }
    }
    //添加订单
    public function add(){

        if(request()->isPost()){
            $data=input('post.');
            $res=$this->db->add($data);
            if ($res['valid']) {
                $this->success($res['msg'], 'index');
            } else {
                $this->error($res['msg']);
            }
        }
    }
    public function orders(){
        //处理title
        $conf = ['title'=>'阿里巴巴1688.com - 订单详情','css'=>'orders','js'=>'orders'];
        $this->assign('conf',$conf);
        $goodsData = db('goods')
            ->alias('g')
            ->join('__ORDER__ o', 'g.gid = o.gid')
            ->join('__ORDER-LIST__ ol','g.gid = ol.gid')
            ->select();
        $this->assign('goodsData', $goodsData);
        //视图
        return view();
    }

}